<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Contact extends CI_model {

	protected $_table_name = 'h_client_contact';
	protected $_key_name = 'client_contact_id';

	function get_contact($verify_code) {

		$this -> db -> where('ref_client_verify_code', $verify_code);
		$query = $this -> db -> get($this -> _table_name);
		return $query -> result();

	}


	function get_contact_json($verify_code) {

		
		$this -> db -> where('ref_client_verify_code', $verify_code);		
		$result = $this -> db -> get($this -> _table_name);
		$p = array();
		foreach ($result->result() as $val) {
			$p[$val -> client_contact_id]["client_contact_id"] = urlencode($val -> client_contact_id);
			$p[$val -> client_contact_id]["name"] = urlencode($val -> name);
			$p[$val -> client_contact_id]["mobile"] = urlencode($val -> mobile);			
		}
		return $p;
	}


	function get_contact_by_id($id) {

		$this -> db -> where($this -> _key_name, $id);
		$query = $this -> db -> get($this -> _table_name);
		return $query -> result();

	}

	function get_contact_by_name_verify($verify_code, $name) {

		$this -> db -> where('ref_client_verify_code', $verify_code);
		$this -> db -> where('name', $name);

		$query = $this -> db -> get($this -> _table_name);

		return $query;
	}

	function insert_contact($contact_data) {

		$this -> db -> insert($this -> _table_name, $contact_data);

	}


	

	function update_contact($data, $id) {
		echo $id;
		//$this->db->where($this->_key_name , $id);
		//$this->db->update($this->_table_name , $data);

	}

	function get_all_contact() {

		return $this -> db -> get($this -> _table_name);
		

	}

}
